\documentclass[a4paper,twoside,11pt,pdftex,norsk]{report}

%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MonKey bachelors thesis %
%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{mdwlist} % itemize closer
\usepackage{multirow}
\usepackage{parskip}
\usepackage{float}
\usepackage{subfigure}
\usepackage{tikz}
\usepackage[utf8]{inputenc}     % For utf8 encoded .tex files
\usepackage{textcomp}
\usepackage[absolute]{textpos}
\usepackage[T1]{fontenc}
\usepackage{cite}
\usepackage[norsk]{babel}
\usepackage{listings,graphicx,mathpple,textcomp,varioref,pdfpages,geometry} % For inclusion of graphics
\usepackage[toc,page]{appendix}
\usepackage[flushleft]{threeparttable}
\usepackage{fancyhdr}
\usepackage{verbatim}
\pagestyle{fancy}
\usepackage{color}
\geometry{a4paper, top=2.0cm, left=3.0cm, right=3.0cm, bottom=2.5cm, includehead, includefoot}
\usepackage{sverb}

\usepackage{epigraph}
\setlength\epigraphwidth{16cm}
\setlength\epigraphrule{0pt}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\epigraph}{\@epitext{#1}}{\itshape\@epitext{#1}}{}{}
\makeatother
%\usepackage[compact]{titlesec}

%\titlespacing{\section}{0pt}{5ex}{0ex}
%\titlespacing{\subsection}{0pt}{5ex}{0ex}
%\titlespacing{\subsubsection}{0pt}{5ex}{0ex}
\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
\definecolor{mymauve}{rgb}{0.58,0,0.82}
\definecolor{black}{rgb}{0,0,0}
% xleftmargin=17pt, framexleftmargin=17pt, framexrightmargin=5pt, framexbottommargin=4pt

% escapeinside={\%*}{*)}{\#*},
\lstset{ 
backgroundcolor=\color{white}, 
basicstyle=\scriptsize, breakatwhitespace=false, 
breaklines=true, commentstyle=\color{mygreen}, 
deletekeywords={...}, 
extendedchars=\true, frame=single, keywordstyle=\color{blue}, 
language=Octave, morekeywords={*,...}, numbers=left, 
numbersep=6pt, stepnumber=1, numberstyle=\tiny\color{mygray}, 
rulecolor=\color{black}, showspaces=false, showstringspaces=false, 
showtabs=false, stringstyle=\color{mymauve}, tabsize=2, title=\lstname, 
xleftmargin=3em, framexrightmargin=5pt, framexbottommargin=4pt 
}

% Ikke for vedlegg
\lstdefinestyle{example}{language=java,frame=single,numbers=none,xleftmargin=3em,framexrightmargin=1em,xrightmargin=3em,framexbottommargin=4pt,backgroundcolor={},identifierstyle={},keywordstyle=\color{black},commentstyle=\color{black},stringstyle=\color{black}}


% Norwegian characters for code
\lstset{literate=%
{æ}{{\ae}}1
{å}{{\aa}}1
{ø}{{\o}}1
{Æ}{{\AE}}1
{Å}{{\AA}}1
{Ø}{{\O}}1
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% HYPERREF
\usepackage[colorlinks,pagebackref,pdfusetitle,urlcolor=blue,citecolor=blue,linkcolor=blue,bookmarksnumbered,plainpages=false]{hyperref}
% For print version, use this instead:
%\usepackage[pdfusetitle,bookmarksnumbered,plainpages=false]{hyperref}
%\usepackage{backref}
%\renewcommand{\backrefpagesname}{Cited on}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{includepdfpage}
\newcounter{currentpagecounter}
\newcommand{\addlabelstoallincludedpages}[1]{
   \refstepcounter{includepdfpage}
   \stepcounter{currentpagecounter}
	\appendix
   \label{#1.\thecurrentpagecounter}}
\newcommand{\modifiedincludepdf}[3]{
    \setcounter{currentpagecounter}{0}
    \includepdf[pages=#1,pagecommand=\addlabelstoallincludedpages{#2}]{#3}}


\newenvironment{changemargin}[2]{%
\begin{list}{}{%
\linespread{0.9}% linespace between code
\setlength{\topsep}{0pt}%
\setlength{\leftmargin}{#1}%
\setlength{\rightmargin}{#2}%
\setlength{\listparindent}{\parindent}%
\setlength{\itemindent}{\parindent}%
\setlength{\parsep}{\parskip}%
}%
\item[]}{\end{list}}

\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}

\linespread{1.0}

\title{Rapport, Monitoring is Key}
\author{Øyvind Sigerstad, Nils Slåen og Bjørn-Erik Strand}

\predisplaypenalty=10000
\tolerance = 6000 % Hvor mange ord kan paa hver linje
\hbadness = \tolerance

\pretolerance = 6000
%\pretolerance = 8000

\raggedbottom

\begin{document}
\begin{titlepage}
\includepdf[pages=-]{forside.pdf}
%\begin{center}

% Upper part of the page. The '~' is needed because \\
% only works if a paragraph has started.
%\includegraphics[width=0.50\textwidth]{higlogo}~\\[1cm]

%\textsc{\LARGE Høgskolen i Gjøvik}\\[1.5cm]

%\textsc{\Large Rapport}\\[0.5cm]

% Title
%\HRule \\[0.4cm]
%{ \huge \bfseries MonKey}\\[0.4cm]
%{ \large \emph{"Monitoring is Key"}} \\ [0.3cm]
%\HRule \\[1.5cm]

% Author and supervisor
%\begin{minipage}{0.4\textwidth}
%\begin{flushleft} \large
%\emph{Av:}\\
%Øyvind Sigerstad\\
%Nils Slåen\\
%Bjørn-Erik Strand
%\end{flushleft}
%\end{minipage}
%\begin{minipage}{0.4\textwidth}
%\begin{flushright} \large
%\emph{Veileder:} \\
%Erik Hjelmås
%\end{flushright}
%\end{minipage}

%\vfill

% Bottom of the page
%{\large \today}

%\end{center}
\end{titlepage}
\pagenumbering{roman}
\includepdf[pages=-,pagecommand={\thispagestyle{plain}}]{sammendrag.pdf}
%\clearpage
%\input{sammendrag}
\includepdf[pages=-,pagecommand={\thispagestyle{plain}}]{forord.pdf}
%\input{deklarasjoner}
\input{ordliste}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TABLE OF CONTENTS, LISTS OF TABLES & FIGURES
%\clearpage
%\newpage
%\pdfbookmark[0]{Contents}{contents_bookmark}
\tableofcontents
\listoftables
%\phantomsection
%\addcontentsline{toc}{chapter}{List of Tables}
\listoffigures
%\phantomsection
%\addcontentsline{toc}{chapter}{List of Figures}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\fancyhead[L]{\small\leftmark}
\fancyhead[R]{\small MonKey - Monitoring is Key}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MAIN THESIS TEXT: arabic page numbering 1, 2, 3, ...
\newpage
\pagenumbering{arabic}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{innledning}
%yo doodsters \ref{opplaering}
%yo dood \ref{kartlegging}
%ja sann kan det gaaaa\cite{servers}

\input{teori}

%See page \pageref{status1.1} till \pageref{status2.1}.

\input{implementasjon}
\input{implementasjon2}
\input{sikkerhet}
\input{dokumentasjon}
\input{avslutning}

% Biblography

\clearpage
\bibliographystyle{ieeetr}
%\bibliographystyle{te}

\addcontentsline{toc}{chapter}{Referanser}
\small{\bibliography{rapport,rapport-books}}
\clearpage

% Appendixes
  \renewcommand\appendixpagename{Vedlegg}
\pagestyle{plain}
\begin{appendices}
\clearpage
\chapter{Arbeidslogg}\label{app:arbeidslogg}
\includepdf[pages=-]{vedlegg/GruppeLogg.pdf}

\chapter{Møtereferater}\label{app:motereferat}
I dette vedlegget ligger møtereferater fra prosjektperioden.
\includepdf[pages=-]{vedlegg/moteref.pdf}

\chapter{Presentasjoner}\label{app:presentasjoner}
I dette vedlegget ligger presentasjoner som har blitt holdt for IKT avdelingen gjennom prosjektet.
\includepdf[pages=-,landscape=true]{vedlegg/15_01_2013forprosjektmote.pdf}
\includepdf[pages=-,landscape=true]{vedlegg/29_01_2013Icinga.pdf}
\includepdf[pages=-,landscape=true]{vedlegg/05_03_2013ServerogInfrastruktur.pdf}

\chapter{Dokumenter}\label{app:dokumenter}
I dette vedlegget finnes:\\ 
\indent Kartlegging av behov, som ble laget av MonKey og utredet sammen med IKT-avdelingen.\\
\indent Opplæringsdokument som ble gjennomgått sammen med Oppdragsgiver og Teknisk kontakt ved slutten av prosjektperioden.
\includepdf[pages=-, pagecommand={\label{kartlegging}}]{vedlegg/kartlegging}
\includepdf[pages=-, pagecommand={\label{opplaering}}]{vedlegg/Opplaering}
\includepdf[pages=-, pagecommand={\label{agentguide}}]{vedlegg/installagent.pdf}

\chapter{Statusrapporter}\label{app:statusrapporter}
I dette vedlegget finnes statusrapporter skrevet for hver iterasjon.
%\modifiedincludepdf{-}{status2}{status/status2.pdf}

\includepdf[pages=-]{status/status1.pdf}
\includepdf[pages=-]{status/status2.pdf}
\includepdf[pages=-]{status/status3.pdf}
\includepdf[pages=-]{status/status4.pdf}
\includepdf[pages=-]{status/status5.pdf}
\includepdf[pages=-]{status/status6.pdf}
\chapter{Gantt-skjema}\label{app:gantt}
I dette vedlegget er Gantt-skjema for prosjektet slik det ble gjennomført.  
\includepdf[pages=-]{gantt_gjennomforing.pdf}
\chapter{Forprosjekt}\label{app:forprosjekt} I dette vedlegget finnes forprosjektet for MonKey.  %\modifiedincludepdf{-}{forprosjekt}{forprosjekt.pdf}
\includepdf[pages=-]{forprosjekt.pdf}

\chapter{Kildekode}\label{app:kildekode}
Selvprodusert kildekode er lagt ved under dette vedlegget. Innholder plugin-er, script for generering av host og kontakter, init-script, SQL brukeroppretting (ikke skrevet selv) og differansen på endrede plugin-er.
\begin{changemargin}{-1cm}{-1cm}

\section{Host-generering}
\lstinputlisting[language=Bash, label={gen.bash}]{script/gen.bash}

\section{Synkronisering av kontakter fra Active Directory}
\lstinputlisting[language=Perl, label={ad_sync.pl}]{script/ad_sync.pl}

\section{Check NDB Mem}
\lstinputlisting[language=Perl, label={check_ndb_mem.pl}]{script/check_ndb_mem.pl}
\clearpage

\section{Brukeroppretting for SQL-motorer}
\lstinputlisting[language=sql, label={oracledb.sql}]{script/oracledb.sql}
\lstinputlisting[language=sql, label={mssqldb.sql}]{script/mssqldb.sql}

\section{Init-script}
\lstinputlisting[language=Bash, label={metricinga_init.d}]{script/metricinga_init.d}

\section{Statusvindu}
\lstinputlisting[language=PHP, label={index.php}]{script/index.php}
\lstinputlisting[language=PHP, label={nagdash.php}]{script/nagdash.php}
\lstinputlisting[language=PHP, label={netbotz.php}]{script/netbotz.php}
\lstinputlisting[language=PHP, label={rss.php}]{script/rss.php}
\lstinputlisting[language=PHP, label={image.php}]{script/image.php}
\lstinputlisting[language=PHP, label={footprints.php}]{script/footprints.php}
\lstinputlisting[language=PHP, label={config.php}]{script/config.php}
\lstinputlisting[language=PHP, label={db_config.php}]{script/db_config.php}
\lstinputlisting[language=PHP, label={external.js}]{script/external.js}
\clearpage
\lstinputlisting[language=HTML, label={style.css}]{script/style.css}
\clearpage
\section{Differanse på endrede plug-ins}
\inputencoding{latin1}
\lstinputlisting[label={diff.pl}]{vedlegg/diff.pl}
\end{changemargin}

\chapter{E-post}\label{epost}
E-poster av relevans for rapporten. Svar er fjernet av hensyn til mottaker.
\clearpage
\verbatiminput{vedlegg/customvariable_mail.txt}
\noindent\rule{\textwidth}{0.4pt}
\verbatiminput{vedlegg/nagdashauthor_mail.txt}
\noindent\rule{\textwidth}{0.4pt}
\verbatiminput{vedlegg/hwgroup_mail.txt}
\clearpage
\verbatiminput{vedlegg/wathergoose_mail.txt}
\noindent\rule{\textwidth}{0.4pt}
\verbatiminput{vedlegg/database_mail.txt}\label{app:maildb}
\clearpage
\verbatiminput{vedlegg/servermiljo_mail.txt}
\clearpage
\verbinput{vedlegg/check_xenapi_mail.txt}\label{app:xenapi}
\end{appendices}
\end{document}
